#include<iostream>
using namespace std;
class CMatrix;
class CVector
{
    private:
        int *data;
        int n;
    public:
        CVector()
        {
            n=5;
            data=new int[n];
            for(int i=0;i<n;i++)
            {
                data[i]=i;
            }
        }
        CVector(int nn)
        {
            n=nn;
            data=new int[nn];
            for(int i=0;i<nn;i++)
            {
                data[i]=0;
            }
        }
        CVector(int n1,int* a)
        {
            data=new int[n1];
            n=n1;
            for(int i=0;i<n1;i++)
            {
                data[i]=a[i];
            }
        }
        void Print()
        {
            for(int i=0;i<n;i++)
            {
                if(i!=0)
                    cout<<" ";
                cout<<data[i];
            }
            cout<<endl;
        }
        ~CVector()
        {
            if(data)
                delete[] data;
        }
        friend CMatrix;
        CVector(const CVector& tmp)
        {
            n = tmp.n;
            data = new int[n];
            for (int i = 0; i < n; i++)
            {
                data[i] = tmp.data[i];
            }
        }
};
class CMatrix
{
    private:
        int n;
        int **data;
    public:
        CMatrix(int n1,int **dataNum)
        {
            n=n1;
            data=new int*[n1];
            for(int i=0;i<n;i++)
            {
                data[i]=new int[n1];
            }
            for(int i=0;i<n;i++)
            {
                for(int j=0;j<n;j++)
                {
                    data[i][j]=dataNum[i][j];
                }
            }
        }

        bool Judge(const CVector& c1)
        {
            return n==c1.n;
        }
        CVector multi(const CVector &v1)
        {
            CVector ans(v1.n);
            for(int i=0;i<n;i++)
            {
                for(int j=0;j<n;j++)
                {
                    ans.data[i]+=v1.data[j]*data[i][j];
                }
            }
            return ans;
        }
};

int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        int **numbe=new int*[n];
        for(int i=0;i<n;i++)
        {
            numbe[i]=new int[n];
        }
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<n;j++)
            {
                cin>>numbe[i][j];
            }
        }
        CMatrix antmp(n,numbe);
        int m;
        cin>>m;
        int *bntmp=new int[m];
        for(int i=0;i<m;i++)
        {
            cin>>bntmp[i];
        }
        CVector vetmp(m,bntmp);
        if(!antmp.Judge(vetmp))
        {
            cout<<"error"<<endl;
        }
        else
        {
            antmp.multi(vetmp).Print();
        }
        delete[] bntmp;
        delete[] numbe;
    }
}